package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysVideoLearning;
import com.ruoyi.system.service.ISysVideoLearningService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频学习管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-27
 */
@Controller
@RequestMapping("/system/learning")
public class SysVideoLearningController extends BaseController
{
    private String prefix = "system/learning";

    @Autowired
    private ISysVideoLearningService sysVideoLearningService;

    @RequiresPermissions("system:learning:view")
    @GetMapping()
    public String learning()
    {
        return prefix + "/learning";
    }

    /**
     * 查询视频学习管理列表
     */
    @RequiresPermissions("system:learning:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysVideoLearning sysVideoLearning)
    {
        startPage();
        List<SysVideoLearning> list = sysVideoLearningService.selectSysVideoLearningList(sysVideoLearning);
        return getDataTable(list);
    }

    /**
     * 导出视频学习管理列表
     */
    @RequiresPermissions("system:learning:export")
    @Log(title = "视频学习管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysVideoLearning sysVideoLearning)
    {
        List<SysVideoLearning> list = sysVideoLearningService.selectSysVideoLearningList(sysVideoLearning);
        ExcelUtil<SysVideoLearning> util = new ExcelUtil<SysVideoLearning>(SysVideoLearning.class);
        return util.exportExcel(list, "视频学习管理数据");
    }

    /**
     * 新增视频学习管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存视频学习管理
     */
    @RequiresPermissions("system:learning:add")
    @Log(title = "视频学习管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysVideoLearning sysVideoLearning)
    {
        return toAjax(sysVideoLearningService.insertSysVideoLearning(sysVideoLearning));
    }

    /**
     * 修改视频学习管理
     */
    @RequiresPermissions("system:learning:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysVideoLearning sysVideoLearning = sysVideoLearningService.selectSysVideoLearningById(id);
        mmap.put("sysVideoLearning", sysVideoLearning);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频学习管理
     */
    @RequiresPermissions("system:learning:edit")
    @Log(title = "视频学习管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysVideoLearning sysVideoLearning)
    {
        return toAjax(sysVideoLearningService.updateSysVideoLearning(sysVideoLearning));
    }

    /**
     * 删除视频学习管理
     */
    @RequiresPermissions("system:learning:remove")
    @Log(title = "视频学习管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysVideoLearningService.deleteSysVideoLearningByIds(ids));
    }


    @PostMapping( "/get")
    @ResponseBody
    public AjaxResult getList( SysVideoLearning sysVideoLearning){
        return success(sysVideoLearningService.selectSysVideoLearningList(sysVideoLearning));
    }

}
